<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示所有汽车信息</title>
</head>
<style type="text/css">
	.hide{ display: none;}
</style>
<script type="text/javascript" src="../jquery-3.2.0.min.js"></script>
<script type="text/javascript">
function fun() {
	if($("#id").val()==""){
		alert("用户名不能为空!");
		return;
	}else{
		$.get("${pageContext.request.contextPath }/CheckCarServlet",
			{id:$("#id").val()
			},
			function(data){
				$("span").html(data);
			}
		)
	}
}
</script>
<body>
<%= session.getAttribute("user") %>
你可以使用以下功能<br>
<ul>
<li><a href="${pageContext.request.contextPath}/ShowCarServlet">显示汽车信息</a></li>
<li>
<form action="${pageContext.request.contextPath}/SelectCarByIdServlet" method="post">
关键词查询:<input type="text" name="selectKey">
<input type="submit" value="查询">
</form>
</li>
<li>插入数据<br>
<form action="${pageContext.request.contextPath}/InsertCarServlet" method="post">
id:<input type="text" name="id" onchange="fun()" id="id">
<span></span>
<br>
name:<input type="text" name="name">&nbsp;&nbsp;&nbsp;
type:<input type="text" name="type">&nbsp;&nbsp;&nbsp;
price:<input type="text" name="price"><br>
<input type="submit" value="插入"> 
</form>
</li>
<li><a href="${pageContext.request.contextPath}/exp5/input.jsp">修改密码</a></li>
<li><a href="${pageContext.request.contextPath}/LogoutServlet">销毁账号</a></li>
<li><a href="login.jsp">退出登录</a></li>
</ul>
<hr>
<c:if test="${not empty list }">
<table>
<tr>
<th> 序号</th>
<th> 车名</th>
<th> 型号</th>
<th> 价格</th>
</tr>
		<c:forEach items="${list }" var="car"> 
    <tr>
        <td>${car.car_id }</td>
        <td>${car.car_name }</td>
        <td>${car.car_type }</td>
        <td><fmt:formatNumber value="${car.car_price }" type="number" pattern=".00"></fmt:formatNumber></td>
        <td>
        <form action="${pageContext.request.contextPath }/exp6/exit.jsp">
        <input type="text" class="hide" name="id" value="${car.car_id }">
        <input type="text" class="hide" name="name" value="${car.car_name }">
        <input type="text" class="hide" name="type" value="${car.car_type }">
        <input type="text" class="hide" name="price" value="${car.car_price }">
        <input type="submit" value="修改">
        </form>
        <form action="${pageContext.request.contextPath }/DeleteCarServlet">
        <input type="text" class="hide" name="id" value="${car.car_id }">
        <input type="submit" value="删除">
        </form>
        </td>
    </tr>
    </c:forEach>

<tr> 
<td colspan="4">${bar}</td>
</tr>
<tr align="center">
<td colspan="4">
<form action="${pageContext.request.contextPath}/ShowCarServlet">
每页显示<input type="text" name="number" value="${empty number?10:number}">条
<input type="submit" value="确定">
</form>
</td>
</tr>
</table>
</c:if>
<c:if test="${empty list }">
请点击上方的超链接或用关键字查询，获得数据之后在操作
</c:if>
</body>
</html>